package com.uidt.project.ptsj.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.uidt.framework.aspectj.lang.annotation.Log;
import com.uidt.framework.aspectj.lang.enums.BusinessType;
import com.uidt.project.ptsj.domain.Rank;
import com.uidt.project.ptsj.service.IRankService;
import com.uidt.framework.web.controller.BaseController;
import com.uidt.framework.web.domain.AjaxResult;
import com.uidt.common.utils.poi.ExcelUtil;
import com.uidt.framework.web.page.TableDataInfo;

/**
 * 红黑榜Controller
 * 
 * @author uidt
 * @date 2024-08-22
 */
@RestController
@RequestMapping("/ptsj/rank")
public class RankController extends BaseController
{
    @Autowired
    private IRankService rankService;

    /**
     * 查询红黑榜列表
     */
//    @PreAuthorize("@ss.hasPermi('ptsj:rank:list')")
    @GetMapping("/list")
    public TableDataInfo list(Rank rank)
    {
        startPage();
        List<Rank> list = rankService.selectRankList(rank);
        return getDataTable(list);
    }

    /**
     * 导出红黑榜列表
     */
    @PreAuthorize("@ss.hasPermi('ptsj:rank:export')")
    @Log(title = "红黑榜", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Rank rank)
    {
        List<Rank> list = rankService.selectRankList(rank);
        ExcelUtil<Rank> util = new ExcelUtil<Rank>(Rank.class);
        util.exportExcel(response, list, "红黑榜数据");
    }

    /**
     * 获取红黑榜详细信息
     */
    @PreAuthorize("@ss.hasPermi('ptsj:rank:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(rankService.selectRankById(id));
    }

    /**
     * 新增红黑榜
     */
    @PreAuthorize("@ss.hasPermi('ptsj:rank:add')")
    @Log(title = "红黑榜", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Rank rank)
    {
        return toAjax(rankService.insertRank(rank));
    }

    /**
     * 修改红黑榜
     */
    @PreAuthorize("@ss.hasPermi('ptsj:rank:edit')")
    @Log(title = "红黑榜", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Rank rank)
    {
        return toAjax(rankService.updateRank(rank));
    }

    /**
     * 删除红黑榜
     */
    @PreAuthorize("@ss.hasPermi('ptsj:rank:remove')")
    @Log(title = "红黑榜", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(rankService.deleteRankByIds(ids));
    }
}
